package com.onepiece.shipelves.common.myutils.map;

public class HashMapUtil {
    private static int MAXIMUM_CAPACITY = Integer.MAX_VALUE;

    public static void main(String[] args) {
        int i = tableSizeFor(10);
        System.out.println(i);

    }

    //找到离提供的数字最近的2的阶乘的数，就是把-1后的数每位都变成1,然后+1
    static final int tableSizeFor(int cap) {
        int n = cap - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
    }
}
